{extend name='base' /}
{block name='content' /}
<!--tab标签-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">管理员管理</li>
                <li class=""><a href="{:url('admin/admin_user/add')}">添加管理员</a></li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form layui-form-pane" action="{:url('admin/admin_user/index')}" method="get">
                        <div class="layui-form-item">
                            <label class="layui-form-label">部门</label>
                            <div class="layui-input-inline" >
                                <select name="did" lay-skin="select">
                                    <option value="">请选择部门</option>
                                    {foreach name="department_list" item="v"}
                                    <option value="{$v.id}" {if condition="$did==$v.id"} selected="selected"{/if}>{$v.title}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <label class="layui-form-label">权限组</label>
                            <div class="layui-input-inline" >
                                <select name="gid" lay-skin="select">
                                <option value="">请选择权限组</option>
                                {foreach name="auth_group_list" item="v"}
                                <option value="{$v.id}" {if condition="$gid==$v.id"} selected="selected"{/if}>{$v.title}</option>
                                {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键词</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键词" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn">搜索</button>
                            </div>
                            <div class="layui-inline">
                                <a href="{:url('admin/admin_user/index',['cleanup'=>'cleanup'])}" class="layui-btn layui-btn-danger">清除</a>
                            </div>
                        </div>
                    </form>
                    <hr>
                    <form class="layui-form" action="">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th style="width: 30px;">ID</th>
                                <th>部门</th>
                                <th>权限组</th>
                                <th>管理员名</th>
                                <th>姓名</th>
                                <th>手机</th>
                                <th>状态</th>
                                <th style="width: 130px;">创建时间</th>
                                <th style="width: 80px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="admin_user_list" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{if condition="$vo.did neq null"}{$vo.department.title}{else}总部门{/if}</td>
                                <td>{$vo.title}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.mobile}</td>
                                <td><input type="checkbox" name="status" lay-skin="switch" lay-filter="switchTest" value="{$vo.id}" lay-text="启用|禁用" {if condition="$vo.status==1"}checked{/if}></td>
                                <td>{$vo.create_time}</td>
                                <td>
                                    <div class="layui-btn-group">
                                        <a href="{:url('admin/admin_user/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm" title="编辑"><i class="layui-icon">&#xe642;</i></a>
                                        <a href="{:url('admin/admin_user/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm ajax-delete" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </form>
                    <!--分页-->
                    {$admin_user->render()}
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['layer','form'], function(){ //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
        var form = layui.form;

        /**
         * 通用删除
         */
        $('.ajax-delete').on('click', function () {
            var _href = $(this).attr('href');
            layer.open({
                shade: false,
                content: '确定删除？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _href,
                        type: "get",
                        success: function (info) {
                            if (info.code === 1) {
                                setTimeout(function () {
                                    location.href = info.url;
                                }, 1000);
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            if(this.checked==true){
                var status=1;
            }else{
                var status=0;
            }
            $.ajax({
                url: "{:url('admin/admin_user/update')}?id="+this.value+"&status="+status,
                type: "get",
                success: function (info) {
                    setTimeout(function () {
                        location.href = info.url;
                    }, 1000);
                    layer.msg(info.msg);
                }
            });
            return false;
        });

    });
</script>
{/block}